const express = require("express")
const {resolve} = require("path")
const model = require("../db/model")
const router = express.Router()
router.get("/registe",(req,res)=>{
    res.sendFile(resolve(__dirname,"../view","registe.html"))
})
router.get("/login",(req,res)=>{
    res.sendFile(resolve(__dirname,"../view","login.html"))
})
router.get("/detail",async (req,res)=>{
    const {id} = req.cookies
    if(id){
        const user = await model.findOne({ _id: req.cookies.id })
        if(user){
            res.sendFile(resolve(__dirname,"../view","detail.html"))
        }else{
            res.redirect('http://localhost:5000/login')
        }
    }else{
        res.redirect('http://localhost:5000/login')
    }
})
module.exports = router